package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api("C端购物车接口")
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;
    /**
     * 添加购物车
     */
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result insertSC(@RequestBody ShoppingCartDTO shoppingCartDTO){

        shoppingCartService.insertSC(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查看购物车信息")
    public Result<List<ShoppingCart>> showSC(){

        List<ShoppingCart> listSC = shoppingCartService.showSC();
        return Result.success(listSC);
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result cleanSC(){
        shoppingCartService.cleanSC();
        return Result.success();
    }

}
